package com.example.spring.ai.controller;

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ai/embed")
public class EmbeddingController {

    private final EmbeddingModel embeddingModel;

    @Autowired
    public EmbeddingController(EmbeddingModel embeddingModel) {
        this.embeddingModel = embeddingModel;
    }

    @RequestMapping("/chat")
    public EmbeddingResponse chat(@RequestParam(value = "message", defaultValue = "讲个笑话") String message) {
        return embeddingModel.call(new EmbeddingRequest(List.of(message),
                OpenAiEmbeddingOptions.builder()
                        .model("BAAI/bge-m3")
                        .build()));
    }
}
